package com.tedu.interceptor.config;

import com.tedu.interceptor.interceptor.MyInterceptor;
import com.tedu.interceptor.interceptor.MyInterceptor1;
import com.tedu.interceptor.interceptor.MyInterceptor2;
import com.tedu.interceptor.interceptor.MyInterceptor3;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class Config implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        //注册后,SpringMVC框架就会使用这个拦截器
        //如果我们没有指定拦截的路径,那么默认拦截所有请求
        /*
        * http://localhost:8080/users/reg           拦截
        * http://localhost:8080/index.html          拦截
        * http://localhost:8080/users/login         拦截
        * http://localhost:8080/123.html            拦截
        *
        * */
        //registry.addInterceptor(new MyInterceptor());

        /*
         *可以指定拦截的路径
         * http://localhost:8080/users/reg           拦截
         * http://localhost:8080/index.html          不拦截
         * http://localhost:8080/users/login         不拦截
         * http://localhost:8080/123.html            不拦截
        * */
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/reg");*/

        /*
        * 可以指定多个拦截路径
         *  http://localhost:8080/users/reg          拦截
         * http://localhost:8080/index.html          不拦截
         * http://localhost:8080/users/login         拦截
         * http://localhost:8080/123.html            不拦截
        * */
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/reg","/users/login");*/

        /*
        * http://localhost:8080/users/reg                   拦截
        * http://localhost:8080/users/login                 拦截
        * http://localhost:8080/users/logout                拦截
        * http://localhost:8080/users/findById              拦截
        * http://localhost:8080/users/update                拦截
        * ...
        * 如上用户的相关操作都需要过滤
        *
        * 可以使用"**"通配符,例如:"/users/**" 此时只要请求路径包含/users/...
        * 后面的请求路径部分是什么都要走拦截器
        * */
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/**");*/

        /*
         * http://localhost:8080/users/reg                   拦截
         * http://localhost:8080/users/login                 不拦截
         * http://localhost:8080/users/logout                不拦截
         * http://localhost:8080/users/findById              拦截
         * http://localhost:8080/users/update                拦截
        * */
       /* registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/**")
                .excludePathPatterns("/users/login","users/logout");*/

        //注册三个拦截器
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
        registry.addInterceptor(new MyInterceptor3());
    }
}
